package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.mapper.CheckItemMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;


@Service
@Transactional
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {


    @Override
    public PageResult findPage(QueryPageBean pageBean) {
        Page<CheckItem> page = null;
        PageResult result = null;
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_delete",0);  // 查询有效数据

        //      有条件分页查询  先判断条件是否为空
        if (StringUtils.isEmpty(pageBean.getQueryString())) {

            // mp  无分页查询     先配置 分页插件
            page = page(new Page<CheckItem>(pageBean.getCurrentPage(), pageBean.getPageSize()), queryWrapper);

            //无条件查询结果
            result = new PageResult(page.getTotal(), page.getRecords());

            return result;
        } else {
            // 按照名称模糊查询
            queryWrapper.like("name", pageBean.getQueryString());

            //有条件查询结果
            page = page(new Page<CheckItem>(pageBean.getCurrentPage(), pageBean.getPageSize()), queryWrapper);

            result = new PageResult(page.getTotal(), page.getRecords());
        }


        return result;
    }

    @Override
    public List<CheckItem> findAll() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_delete",0);//  有效数据
        List<CheckItem> list = list(queryWrapper);
        return list;

    }

    @Override
    public boolean findById(int id) {
       Object o = baseMapper.findById(id);
        if (o!=null){
            return false;
        }
        return true;
    }


}

